package cn.bigfire.wzdj.util;

import cn.hutool.core.date.DateUtil;

public class DateUtils {

    public static String secondToTime(long seconds) {
        // 定义每个月的天数（为了简化，这里仍然使用30天，但可以根据需要调整）
        final int daysPerMonth = 30;
        // 定义各个时间单位的秒数
        final long SECONDS_IN_MINUTE = 60;
        final long SECONDS_IN_HOUR = 60 * SECONDS_IN_MINUTE;
        final long SECONDS_IN_DAY = 24 * SECONDS_IN_HOUR;
        final long SECONDS_IN_MONTH = daysPerMonth * SECONDS_IN_DAY;

        long months = seconds / SECONDS_IN_MONTH;
        seconds %= SECONDS_IN_MONTH;
        long days = seconds / SECONDS_IN_DAY;
        seconds %= SECONDS_IN_DAY;
        long hours = seconds / SECONDS_IN_HOUR;
        seconds %= SECONDS_IN_HOUR;
        long minutes = seconds / SECONDS_IN_MINUTE;
        long remainingSeconds = seconds % SECONDS_IN_MINUTE;

        StringBuilder timeString = new StringBuilder();

        if (months > 0) {
            timeString.append(months).append("月");
        }
        if (days > 0) {
            timeString.append(days).append("天");
        }
        if (hours > 0) {
            timeString.append(hours).append("时");
        }
        if (minutes > 0) {
            timeString.append(minutes).append("分");
        }
        if (remainingSeconds > 0 || (months == 0 && days == 0 && hours == 0 && minutes == 0)) {
            timeString.append(remainingSeconds).append("秒");
        }

        return timeString.toString().trim();
    }


    public static String secondToTimeSimple(long seconds) {
        // 定义每个月的天数（为了简化，这里仍然使用30天，但可以根据需要调整）
        final int daysPerMonth = 30;
        // 定义各个时间单位的秒数
        final long SECONDS_IN_MINUTE = 60;
        final long SECONDS_IN_HOUR = 60 * SECONDS_IN_MINUTE;
        final long SECONDS_IN_DAY = 24 * SECONDS_IN_HOUR;
        final long SECONDS_IN_MONTH = daysPerMonth * SECONDS_IN_DAY;

        long months = seconds / SECONDS_IN_MONTH;
        seconds %= SECONDS_IN_MONTH;
        long days = seconds / SECONDS_IN_DAY;
        seconds %= SECONDS_IN_DAY;
        long hours = seconds / SECONDS_IN_HOUR;
        seconds %= SECONDS_IN_HOUR;
        long minutes = seconds / SECONDS_IN_MINUTE;
        long remainingSeconds = seconds % SECONDS_IN_MINUTE;

        StringBuilder timeString = new StringBuilder();

        if (months > 0) {
            timeString.append(months).append("M");
        }
        if (days > 0) {
            timeString.append(days).append("d");
        }
        if (hours > 0) {
            timeString.append(hours).append("H");
        }
        if (minutes > 0) {
            timeString.append(minutes).append("m");
        }
        if (remainingSeconds > 0 || (months == 0 && days == 0 && hours == 0 && minutes == 0)) {
            timeString.append(remainingSeconds).append("s");
        }
        //yyyy-MM-dd_HH-mm-ss
        return timeString.toString().trim();
    }


    public static void main(String[] args) {
        System.out.println(secondToTime(1858895L));
        System.out.println(secondToTime(1918953L));


    }

}
